package com.jvyou.singleton.hungry;

/**
 * @author 橘柚
 * @version 1.0-SNAPSHOT
 * @Date 2024/7/29 16:00
 * @Description 饿汉式单例模式
 */
public class HungrySingleton {

    private static final HungrySingleton HUNGRY_SINGLETON = new HungrySingleton();

    private String name;

    private HungrySingleton() {
    }

    public static HungrySingleton getInstance() {
        return HUNGRY_SINGLETON;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public static void main(String[] args) {
        for (int i = 0; i < 10; i++) {
            new Thread(() -> System.out.println(HungrySingleton.getInstance().hashCode())).start();
        }
    }

}
